package com.jctrip.hotel.source.xxl.atour;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.jctrip.hotel.common.constant.XxlJobNameConstant;
import com.jctrip.hotel.common.util.JsonUtil;
import com.jctrip.hotel.source.model.CommonJobParam;
import com.jctrip.hotel.source.service.atour.AtourTaskService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: zxy
 * @CreateTime: 2023-09-08 15:15
 * @Description:
 */
@Component
@Slf4j
public class SyncAtourPartRatesOneLongerPopXxlJob extends IJobHandler {

    @Resource
    private AtourTaskService atourTaskService;

    @Override
    @XxlJob(XxlJobNameConstant.SYNC_AUTO_HOTEL_RATES_ONE_LONGER_POP)
    public void execute() throws Exception {
        XxlJobHelper.log(XxlJobNameConstant.SYNC_AUTO_HOTEL_RATES_ONE_LONGER_POP + " xxl job start");
        try {
            CommonJobParam jobParam = JsonUtil.toObject(CommonJobParam.class, XxlJobHelper.getJobParam());
            if (CollectionUtils.isEmpty(jobParam.getSourceIds())) {
                return;
            }
            atourTaskService.syncAtourPartLongerRatesPop(jobParam.getSourceIds(),
                    jobParam.getAddDays(), jobParam.getDays());
        } catch (Exception e) {
            log.error(XxlJobNameConstant.SYNC_AUTO_HOTEL_RATES_ONE_LONGER_POP + "error", e);
        }
        XxlJobHelper.log(XxlJobNameConstant.SYNC_AUTO_HOTEL_RATES_ONE_LONGER_POP + " xxl job end");
    }
}